﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WEBDT.Base
{
    public abstract class BaseController<T> : Controller where T :class
    {
        //
        // GET: /Base/

        public IModel repository;

        public BaseController()
            : this(new BaseModel())
        {

        }

        public BaseController(IModel repository)
        {
            this.repository = repository;
        }

        public virtual ActionResult getAll()
        {
            return View(repository.ListAll<T>());
        }

        public virtual ActionResult Details(int id)
        {
            ViewBag.mess = "Base getbyid";
            return View();
        }
        [HttpGet]
        public virtual ActionResult insert()
        {
            ViewBag.mess = "Base insert";
            return View();
        }

        [HttpPost]
        public virtual ActionResult insert(FormCollection fr)
        {
            ViewBag.mess = "Base insert 1";
            return View();
        }

        [HttpGet]
        public virtual ActionResult update(int id)
        {
            ViewBag.mess = "Base update";
            return View();
        }

        [HttpPost]
        public virtual ActionResult update(FormCollection fr)
        {
            ViewBag.mess = "Base update 1";
            return View();
        }
        public virtual ActionResult delete(int id)
        {
            T item = repository.SelectByID<T>(id);
            repository.Remove<T>(item);
            return RedirectToAction("getall");
        }

        

    }
}
